package com.ruoyi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.order.domain.ShopCommoditye;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.ShopGoodse;
import com.ruoyi.order.service.IShopGoodseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品列表Controller
 * 
 * @author ruoyi
 * @date 2021-12-07
 */
@RestController
@RequestMapping("/order/goods")
public class ShopGoodseController extends BaseController
{
    @Autowired
    private IShopGoodseService shopGoodseService;

    /**
     * 栏目 选择
     * @return
     */
    @GetMapping("/shopCommodity")
    public TableDataInfo shopCommodityeSelect(){
        List<ShopCommoditye> list = shopGoodseService.shopCommodityeSelect();
        return getDataTable(list);
    }

    /**
     * 查询商品列表列表
     */
//    @PreAuthorize("@ss.hasPermi('order:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopGoodse shopGoodse)
    {
        startPage();
        List<ShopGoodse> list = shopGoodseService.selectShopGoodseList(shopGoodse);
        return getDataTable(list);
    }

    /**
     * 导出商品列表列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:export')")
    @Log(title = "商品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopGoodse shopGoodse)
    {
        List<ShopGoodse> list = shopGoodseService.selectShopGoodseList(shopGoodse);
        ExcelUtil<ShopGoodse> util = new ExcelUtil<ShopGoodse>(ShopGoodse.class);
        util.exportExcel(response, list, "商品列表数据");
    }

    /**
     * 获取商品列表详细信息
     */
//    @PreAuthorize("@ss.hasPermi('order:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(shopGoodseService.selectShopGoodseById(id));
    }

    /**
     * 新增商品列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:add')")
    @Log(title = "商品列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopGoodse shopGoodse)
    {
        return toAjax(shopGoodseService.insertShopGoodse(shopGoodse));
    }

    /**
     * 修改商品列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:edit')")
    @Log(title = "商品列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopGoodse shopGoodse)
    {
        return toAjax(shopGoodseService.updateShopGoodse(shopGoodse));
    }

    /**
     * 删除商品列表
     */
    @PreAuthorize("@ss.hasPermi('order:goods:remove')")
    @Log(title = "商品列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(shopGoodseService.deleteShopGoodseByIds(ids));
    }
}
